import { Mob } from './mob.js';
export function Mobs() {
  this.mobArr = [];
  this.resource = null;
}

Mobs.prototype.init = async function(_resource) {
    this.resource = _resource;
}

Mobs.prototype.update = function () {
  this.forEach((mob) => {
    mob.update();
  });
};

Mobs.prototype.merge = async function (life) {
  this.destroy();
  this.mobArr.length = 0;
  for (let val of Object.values(life)) {
    if (val.type === "m") {
      let mob = new Mob(this.resource, val);
      await mob.init();
      this.mobArr.push(mob);
    }
  }
};

Mobs.prototype.draw = function(stage) {
  this.mobArr.forEach(mob => {
    stage.addChild(mob.container);
  })
}

Mobs.prototype.forEach = function (cb) {
  this.mobArr.forEach((mob, index) => {
    cb(mob, index);
  });
};

Mobs.prototype.destroy = function() {
  this.mobArr.forEach(mob => {
    mob.container.destroy();
  });
  this.mobArr = [];
}

Mobs.prototype.deleteByIndex
